<template>
  <el-dialog v-model="visible" :title="title" width="1200" show-footer show-zoom resize @close="close">
    <template #default>
      <el-form ref="formRef" :rules="rules" :model="form" label-align="right" label-width="120" size="default">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="移出仓">{{ form.out_warehouse_name }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="目的仓">{{ form.in_warehouse_name }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="Removal单号">{{ form.backup_warehouse_order_no }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="海外仓入库单">{{ form.shipment_id }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="目的仓地址">{{ form.in_warehouse_address }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注">{{ form.remark }}</el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <vxe-table :data="form.detail" :round="true" height="500">
        <vxe-column field="sku" title="SKU"></vxe-column>
        <vxe-column field="send_fn_sku" title="第三方SKU"></vxe-column>
        <vxe-column field="apply_num" title="申请数量"></vxe-column>
        <vxe-column field="in_warehouse_num" title="收货数量"></vxe-column>
        <vxe-column field="in_warehouse_num" title="差异数量">
          <template #default="{ row }">{{  row.apply_num - row.in_warehouse_num }}</template>
        </vxe-column>
      </vxe-table>
    </template>

    <template #footer>
      <div class="flex justify-center py-2">
        <el-button type="primary" @click="close">关 闭</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup name="ComModal" lang="jsx">
import { getRemovalDetail } from '../api/index'
import { reactive, ref, toRefs } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'

const visible = ref(false)
const loading = ref(false)
const formRef = ref(null)
const emits = defineEmits(['query'])

const data = reactive({
  form: {},
  title: '新增',
  handleType: null,
})
const { form, title, handleType } = toRefs(data)

const statusMap = new Map([
  ['add', '新增'],
  ['edit', '编辑'],
  ['view', '查看'],
  ['in', '入库'],
])

const open = (type, id) => {
  title.value = statusMap.get(type)
  handleType.value = type
  visible.value = true
  if (id) getDetail(id)
}

const getDetail = async (id) => {
  try {
    const res = await getRemovalDetail({
      id
    })
    form.value = res.data
  } catch (e) {
    throw Error(e)
  }
}

const close = () => {
  visible.value = false
}
defineExpose({ open })
</script>
<style lang="scss" scoped>
.borderNone {
  :deep(.el-input__wrapper) {
    border: none;
    box-shadow: none
  }
}
</style>
